<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>文档标题</title>
</head>
<body>
<input class="input" type="text" value="请输入搜索关键字" style="color: gray">

<script>
  window.onload = () => {
    const elements = document.getElementsByClassName("input");
    for (const el of elements) {
      el.onfocus = function () {
        this.style.color = "black";
        if (this.value === "请输入搜索关键字") {
          this.value = "";
        }
      };
      el.onblur = function () {
        this.style.color = "gray";
        if (this.value === "") {
          this.value = "请输入搜索关键字";
        }
      };
    }
  }

</script>
</body>
</html>
